**************************************************************************************************************
**	Replication do-file for "Social Democracy and the Birth of Working-Class Representation in Europe"
**  Purpose: Replicate Tables 3 & H; Figures 7a & D (Germany)
*************************************************************************************************************

/* set the directory */

/**************************
		TABLE 3 Pre-war 
***************************/
use "Germany prewar.dta", clear
keep if reform90==1

zip mp_manual trade_indus by_elections prussiadummy if protestants_pct>75, inflate(spd ) 
estat ic 

zip mp_manual c.trade_indus##c.trade_indus by_elections prussiadummy if protestants_pct>75, inflate(spd ) 
margins, at(trade_indus=(20 30 40 50 60 70 80 90 100)) /* Produce Figure 7a*/
label var trade_indus "Percent Employed in Industry and Trade"
marginsplot, title("") ///
	 		 ytitle("Predicted Probability of Working-Class MP") legend(off) ///
			 addplot(hist trade_indus, yaxis(2)  ysc(axis(2) alt) fcolor(gs6%20) lcolor(gs6%20)) ///
			 graphregion(fcolor(white) ilcolor(white) lcolor(white)) 
eststo ig_zip_squared
estat ic 

/**************************
		TABLE 3 interwar
***************************/
use "Germany interwar.dta", clear
gen spd=(party==100)

zip mp_manual workers_pct prussia, inflate(spd) 
estat ic 

zip mp_manual c.workers_pct##c.workers_pct prussia, inflate(spd) 
estat ic 

/*****************************************************************
TABLE H in the Appendix: Constituencies with a majority Catholics
******************************************************************/
use "Germany prewar.dta", clear
keep if reform90==1

zip mp_manual c.trade_indus##c.trade_indus by_elections prussiadummy if catholics_pct>75, inflate(spd ) 
eststo ig_robust_cath
estat ic
margins, at(trade_indus=(20 30 40 50 60 70 80 90 100))
label var trade_indus "Percent Employed in Industry and Trade"
marginsplot, title("") ///
	 		 ytitle("Predicted Probability of Working-Class MP") legend(off) ///
			 addplot(hist trade_indus, yaxis(2)  ysc(axis(2) alt) fcolor(gs6%20) lcolor(gs6%20)) ///
			 graphregion(fcolor(white) ilcolor(white) lcolor(white)) 

zip mp_manual c.trade_indus##c.trade_indus by_elections prussiadummy, inflate(spd ) 
eststo ig_robust_all
estat ic
margins, at(trade_indus=(20 30 40 50 60 70 80 90 100))
label var trade_indus "Percent Employed in Industry and Trade"
marginsplot, title("") ///
	 		 ytitle("Predicted Probability of Working-Class MP") legend(off) ///
			 addplot(hist trade_indus, yaxis(2)  ysc(axis(2) alt) fcolor(gs6%20) lcolor(gs6%20)) ///
			 graphregion(fcolor(white) ilcolor(white) lcolor(white)) 


/***********************************************
FIGURE D in the Appendix
***********************************************/
use "Germany interwar.dta", clear
gen spd=(party==100)

zip mp_manual c.workers_pct##c.workers_pct prussia, inflate(spd) 
eststo wr_zip_squared
margins, at(workers_pct=(.32(.05).62))
marginsplot, title("") ///
	 		 ytitle("Marginal Effect of Percent Manual", size(4)) ///
			 xlabel(, labsize(4))  ylabel(, labsize(4))  xtitle(, size(4)) ///
			 addplot(hist workers_pct, yaxis(2) xlabel(.20 .30 .40 .45 .50 .60, ///
			 labsize(4) ) ysc(axis(2) alt)  fcolor(gs6%20) lcolor(gs6%20)) ///
			 legend (order(1 "Worker" 2 "Non-Worker" )) graphregion(color(white)) 
				   